#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
map<string,int> p;
map<string,int> c;
int main(){
	int n;
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	string op,od;
	for(int i=1;i<=n;i++){
		cin>>op>>od;
		int ld = od.length();
		bool o=1;
		if(op=="Server"){
			int f[5],t=0;
			memset(f,0,sizeof(f));
			for(int k=0;k<ld;k++){
				if(od[k]>='0'&&od[k]<='9'){
					if(f[t]==0&&od[k]=='0'){
						printf("ERR\n");
						k = ld;
						o = 0;
						break;
					}
					f[t] = f[t]*10 + (od[k]-'0');
				}
				else if((t<=2&&od[k]=='.')||(t==3&&od[k]==':')){
					if((f[t]<0&&t<=2)||(f[t]>255&&t<=2)){
						printf("ERR\n");
						k = ld;o = 0;
						break;
					}
					t++;
				}
				else if(t!=4){
					k = ld;o = 0;
					printf("ERR\n");
				}
			}
			if(t==4&&f[4]>=0&&f[4]<=65535&&o){
				if(p[od]>0){
					printf("FAIL\n");
				}
				else{
					p[od] = i;
					printf("OK\n");
				}
			}
			else if(o){
				printf("ERR\n");
			}
		}
		else{
			int f[5],t=0;
			memset(f,0,sizeof(f));
			for(int k=0;k<ld;k++){
				if(od[k]>='0'&&od[k]<='9'){
					if(f[t]==0&&od[k]=='0'){
						printf("ERR\n");
						k = ld;o = 0;
						break;
					}
					f[t] = f[t]*10 + (od[k]-'0');
				}
				else if((t<=2&&od[k]=='.')||(t==3&&od[k]==':')){
					if((f[t]<0&&t<=2)||(f[t]>255&&t<=2)){
						printf("ERR\n");
						k = ld;o = 0;
						break;
					}
					t++;
				}
				else if(t!=4){
					printf("ERR\n");
					k = ld;o = 0;
					break;
				}
			}
			if(t==4&&f[4]>=0&&f[4]<=65535&&o){
				if(p[od]==0){
					printf("FAIL\n");
				}
				else{
					c[od] = p[od];
					printf("%d\n",c[od]);
				}
			}
			else  if(o){
				printf("ERR\n");
			}
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
